package com.train.forum.config;

/**
 * @date 2023/6/14
 */

import cn.dev33.satoken.stp.StpInterface;
import com.train.forum.pojo.po.User;
import com.train.forum.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * stp接口impl
 *
 * @author mek
 * @date 2023/07/14
 */
@Component
@Slf4j
@RequiredArgsConstructor
    public class StpInterfaceImpl implements StpInterface {
    private final UserService userService;
    /**
     * 返回一个账号所拥有的权限码集合
     *
     * @param loginId   登录id
     * @param loginType 登录类型
     * @return {@link List }<{@link String }>
     * @author 马尔康
     * @data 2023-07-31 11:25:13
     **/
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return null;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     *
     * @param loginId   登录id
     * @param loginType 登录类型
     * @return {@link List }<{@link String }>
     * @author 马尔康
     * @data 2023-07-31 11:25:13
     **/
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        User user = userService.getById(Integer.valueOf(loginId.toString()));
        ArrayList<String> roleList = new ArrayList<>();
        roleList.add(user.getRole());
        return roleList;
    }
}

